<template>
	<view class="main">
		<view class="list">
			<input type="text" maxlength="16" v-model="password" value="" placeholder="请输入密码" placeholder-class="placeholder" />
			<text v-if="show" class="icon-a-qingkongpng iconfont clear ml-auto" @click="clearValue"></text>
		</view>
		<view class="tip">
			密码需为6-16位数字或字母组合
		</view>
		<view class="btn" @click="save">
			完成修改
		</view>
	</view>
</template>

<script>
	import {validatePassword,clearSpace} from '@/common/js/validate.js'
	import {updatePassword} from '../../../apis/login/index.js'
	export default {
		data() {
			return {
				password:'',
				phone:''
			}
		},
		computed:{
			show(){
				return this.password ? true:false
			}
		},
		onLoad(option) {
			this.phone=option.phone
		},
		methods: {
			clearValue(){
				this.password=''
			},
			async save(){
				if(validatePassword(this.password)){
					let data={
						mobile:clearSpace(this.phone),
						password:clearSpace(this.password)
					}
					let res=await updatePassword(data)
					if(res.success){
						// #ifdef APP-PLUS
						plus.nativeUI.toast('密码重置成功,将会自动跳转到登录页面。')
						// #endif
						// #ifndef APP-PLUS
						uni.showToast({
							title:'密码重置成功,将会自动跳转到登录页面。',
							icon:'none'
						})
						// #endif
						// 重新登录页面
						setTimeout(()=>{
							uni.reLaunch({
								url:'../login/login'
							})
						},800)
					}
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.main{
		padding:188rpx 80rpx 0 78rpx;
	}
	.list{
		height: 80rpx;
		display: flex;
		align-items: center;
		border-bottom: solid 1rpx  rgba(0, 0, 0, 0.1) ;
	}
	.tip{
		font-size: 24rpx;
		font-weight: 400;
		color: rgba(0, 0, 0, 0.38);
		margin-top: 18rpx;
	}
	.btn{
		width: 592rpx;
		height: 90rpx;
		background: #3C8EFF;
		text-align: center;
		line-height: 90rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: #FFFFFF;
		margin-top: 158rpx;
		border-radius: 8rpx;
	}
	.clear{
		font-size: 48rpx;
	}

</style>
